package com.example.schedule.springtask;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description:  基于 Spring Frame Workd的
 * @Author: yangzhiwei
 * @Date: 2021/2/6 18:17
 */
@Configuration
@EnableScheduling //启动Spring Task的定时任务 调度的功能
public class SpringTaskConfig {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private  final AtomicInteger counts = new AtomicInteger();

    //@Scheduled(fixedRate = 2000)
    //标准字段 虽然不支持年字段，但是我们可以在 execute方法内实现基于年的逻辑
    @Scheduled(cron = "1-59/3 1-59/1 * * * *" ) //

    public void execute() {
        logger.info("[execute][定时第 ({}) 次执行]", counts.incrementAndGet());
    }
}
